package com.xujiang.myblog.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xujiang.common.util.ToolBarHelper;
import com.xujiang.myblog.Base.CPRXFragment;
import com.xujiang.myblog.R;
import com.xujiang.myblog.ui.AddBlogActivity;
import com.xujiang.myblog.util.L;
import com.xujiang.myblog.util.UIUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xujiang on 2017/4/12.
 */

public class BlogFragment extends CPRXFragment {

    private final static String TAG = BlogFragment.class.getSimpleName();

    @BindView(R.id.rlv_blogfragment)
    RecyclerView rlvBlogfragment;
    @BindView(R.id.fab)
    FloatingActionButton fab;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
            @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_blog, container, false);
        ButterKnife.bind(this, view);

        initToolbar(view);
        L.i(TAG, "oncreateView Blog Fragment");

        rlvBlogfragment.setHasFixedSize(true);
        rlvBlogfragment.setLayoutManager(new LinearLayoutManager(getContext()));
        initAdapter();
        return view;
    }

    private void initToolbar(View view) {
        ToolBarHelper toolbarhelper = ToolBarHelper.with(view);
        Toolbar toolbar = toolbarhelper.getToolbar();
        try {
            setAll(toolbar, R.mipmap.ic_launcher, R.mipmap.user_portrait_hint_sm,
                    "Title test can show how long", "SubTitle test can show how long",
                    R.menu.base_toolbar_menu);
            setDefaultOnclicklistener(toolbar);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initAdapter() {

    }

    //fragment的显示监听
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            Log.i("hepan", "显示封面1");
        }
    }

    @OnClick(R.id.fab)
    public void onClick() {
        //        Snackbar.make(getView(), "Replace with your own action", Snackbar.LENGTH_LONG)
        //                .setAction("Action", null).show();
        UIUtils.startActivity(getContext(), AddBlogActivity.class);

    }
}
